package com.codoon.unova.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * 工具类获取版本号的等
 * 
 * @author Administrator
 * 
 */
public class ApplicationUtil {

	/**
	 * 获取版本号
	 * 
	 * @param context
	 * @return
	 */
	public static int getVersionCode(Context context) {
		int verCode = -1;
		try {
			verCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return verCode;
	}

	/**
	 * 获取版本名称
	 * 
	 * @param context
	 *            :上下文对象
	 * @return
	 */
	public static String getVerName(Context context) {
		String verName = "";
		try {
			verName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return verName;
	}

	

	/**
	 * 发送广播退出程序
	 * 
	 * @param context
	 */
	public static void onExitApplication(final Activity context) {
		try {
			context.finish();
			Intent intent = new Intent();
			intent.setAction(context.getApplicationContext().getPackageName() + ".ExitApplication");
			context.sendBroadcast(intent);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
